<?php
require_once __DIR__ . '/Common.php';

use OSS\OssClient;
use OSS\Core\OssException;

class Osslib
{

    var $ossClient = null;

    var $accessKeyId = "LTAIIvT2EUARNbhu";

    var $accessKeySecret = "A5Ilph9emargxKEALypkuEGE7mXJlX";

    var $endpoint = "img.keniu.site";

    var $bucket = 'kn-upload';

    function __construct()
    {
        $this->ossClient = Common::getOssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint);
    }
    
    // 批量删除OBJS
    function del_IMGS($objs = array())
    {
        if (empty($objs) || ! is_array($objs)) {
            return '必须是数组,且不能为空';
        }
        
        $this->ossClient->deleteObjects($this->bucket, $objs);
    }
    
    // 删除单个OBJ
    function del_IMG($obj = '')
    {
        return $this->ossClient->deleteObject($this->bucket, $obj);
    }
    
    // 查看当前全部目录列表
    function listBuckets()
    {
        $listObjectInfo = $this->ossClient->listObjects($this->bucket);
        $objectList = $listObjectInfo->getObjectList();
        
        if (! empty($objectList)) {
            foreach ($objectList as $objectInfo) {
                print($objectInfo->getKey() . "\t" . $objectInfo->getSize() . "\t" . $objectInfo->getLastModified() . "\n");
            }
        }
    }
}

